home *** CD-ROM | disk | FTP | other *** search
INI File | 2001-09-10 | 8.7 KB | 168 lines |
- [Name]
- Lines v1.0 - Provides events for drawing simple lines
- By Matthew Peterson, matthew@pinoko.berkeley.edu
-
- [Description]
- 2-19-2000
- This behavior consists of 2 functions. To use these functions,
- place this behavior on any sprite. Set the input Global Variables, and
- Execute the functions.
- Note: Each line is a sprite. You must provide the ID of the sprite you would
- like to turn into a line. You may use MakeNewSprite( ) if you want
- to produce new sprites during runtime of your wired movie.
-
- DrawLine : This event uses 8 Input Global Variables:
- LineSpriteID -- the id of the line (which is a sprite)
- LineThickness -- The thickness of the line. Positive Float.
- LineImageIndex -- The image (color) of the line.
- DoThicknessOffset -- Set to true if you want the line to
- slightly extend beyond the start and
- end points. Most drawing programs
- have this attribute set to true.
- LineStartx -- The x position of the start of the line.
- LineStarty -- The y position of the start of the line.
- LineEndx -- The x position of the end of the line.
- LineEndy -- The y position of the end of the line.
-
- DrawLinePolar : This event uses 8 Input Global Variables:
- LineSpriteID -- the id of the line (which is a sprite)
- LineThickness -- The thickness of the line. Positive Float.
- LineImageIndex -- The image (color) of the line.
- DoThicknessOffset -- Set to true if you want the line to
- slightly extend beyond the start and
- end points. Most drawing programs
- have this attribute set to true.
- LineStartx -- The x position of the start of the line.
- LineStarty -- The y position of the start of the line.
- LineAngle -- The angle of the line.
- LineLength -- The length of the line.
-
-
- Example: Make spriteofid(2) into a line of thickness 3.
- Draw the line from (7,5) to (25,10).
-
- GlobalVars LineThickness LineSpriteID LineImageIndex DoThicknessOffset lineStartx lineStarty LineEndx LineEndy
-
- LineSpriteID = 2
- LineThickness = 3
- LineImageIndex = 5 //set the image to index 5, some colored square image.
- DoThicknessOffset = TRUE //This adds a slight lip to the ends of the line. It helps in
- // appending multiple lines. TRUE in most drawing programs.
- lineStartx = 7
- lineStarty = 5
- lineEndx = 25
- lineEndy = 10
-
- SpriteOfID(1).ExecuteEvent($DrawLine) //Assuming this behavior is in spriteofid(1).
-
-
- Revision History:
-
-
- [Parameters]
-
-
- [200050 MP_DoLineTrig]
- GlobalVars LineSpriteID lineAngle linelength lineStartx lineStarty LineEndx LineEndy MP_LineT MP_LINEp45 MP_inverted MP_Linediffx MP_Linediffy MP_lineAnglesign MP_lineAnglepolarity
- //This function does the ATan and SquareRoot calculations in order to determine the length and angle
- //of the line between the LineStart and LineEnd. They are the same functions found in the TrigMath behavior.
-
- //First find the x and y distance between the start and the end of the line
- MP_Linediffx = (lineStartx-LineEndx)
- MP_Linediffy = (lineStarty-LineEndy)
-
- MP_LineT = ABS(MP_Linediffx)/ ABS(MP_Linediffy) // The tangent ratio for the line.
-
- //Now, correct for errors in the calculation of ArcTan evident when the angle is around 45 degrees.
- MP_LINEp45 = 0 //45 degree correction factor gets initialized.
- IF ( MP_LineT > 0.65 AND MP_LineT < 1.6) //If the ratio is in the "bad" zone, then let's get it out of there.
- //by rotating the line, then doing the calculation, and then rotating it back.
- //First we will set up the dimensions of the line:
- spriteofid(LineSpriteID).Stretch(lineStartx,lineStarty,LineEndx,lineStarty,LineEndx,LineEndy,lineStartx,LineEndy)
- spriteofid(LineSpriteID).Rotate(45) //rotate to get it out of the bad zone. and now, calculate the new difference:
- MP_Linediffx = spriteofid(LineSpriteID).FirstCornerX - spriteofid(LineSpriteID).ThirdCornerX
- MP_Linediffy = spriteofid(LineSpriteID).FirstCornerY - spriteofid(LineSpriteID).ThirdCornerY
- //Rotate(-45) //We could rotate it back, but there is no need to do this since we'll be stretching it into a line.
- MP_LINEp45 = -45
- ENDIF
-
- //The ATan function we are using, only takes input from the first quadrant. But since
- //we want to determine the full angle, we will need to reflect the result to get
- //into the other quadrants. There are four possibilities:
- IF (ABS(MP_Linediffx) < ABS(MP_Linediffy))
- MP_inverted = 90
- MP_lineAnglesign = -1
- MP_LineT = MP_Linediffx/MP_Linediffy
- IF (MP_Linediffy>1)
- MP_lineAnglepolarity = 0
- ELSE
- MP_lineAnglepolarity = 180
- ENDIF
- ELSE
- MP_lineAnglesign = 1
- MP_inverted = 0
- MP_LineT = MP_Linediffy/MP_Linediffx
- IF (MP_Linediffx<1)
- MP_lineAnglepolarity = 0
- ELSE
- MP_lineAnglepolarity = 180
- ENDIF
- ENDIF
- //Now, We calculate the first quadrant aTan.
- lineAngle=MP_LineT*(1+MP_LineT*MP_LineT*(-1/3+MP_LineT*MP_LineT*(1/5+MP_LineT*MP_LineT*(-1/7+MP_LineT*MP_LineT*(1/9-MP_LineT*MP_LineT/11)))))
- //Then we reflect and invert if needed to get into the other quadrants. Plus we add our 45degree correction factor (LINE45)
- lineAngle = MP_lineAnglesign*(lineAngle*180/PI + MP_inverted) - MP_lineAnglepolarity + MP_LINEp45
-
- //So far, we have calculated our angle. All that is left is to calculate the length of the line.
- //To do that we need a sqrt function, but we can be cleaver, and use the angle we just determined
- //to calculate the sqrt for us:
- IF (lineAngle = -180)
- linelength = lineStartx - lineEndx
- ELSE
- spriteofid(LineSpriteID).Stretch(lineStartx,lineStarty,LineEndx,lineStarty,LineEndx,LineEndy,lineStartx,LineEndy)
- spriteofid(LineSpriteID).Rotate(-lineAngle)
- linelength = spriteofid(LineSpriteID).BoundsRight - spriteofid(LineSpriteID).BoundsLeft
- ENDIF
- //That's it. We have all we need to draw our line: The angle to rotate, and the length.
- //The End. By Matthew.